package com.tanhua.mqlistener;

import com.tanhua.domain.Log;
import com.tanhua.mapper.LogMapper;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@RocketMQMessageListener(
    topic = "tanhua-log",
    consumerGroup="tanhua-c"
)
public class LogListener implements RocketMQListener<Map> {

    @Autowired
    private LogMapper logMapper;

    @Override
    public void onMessage(Map map) {

        //取数据
        Integer userId = Integer.parseInt((String) map.get("userId"));
        String type = (String)map.get("type");
        String logTime = (String)map.get("logTime");

        //处理业务-记录一条日志
        Log log = new Log();
        log.setUserId(userId.longValue());
        log.setType(type);
        log.setLogTime(logTime);
        logMapper.insert(log);
    }
}
